////
////  ThirdPartAlipay.m
////  Screen
////
////  Created by Season02 on 6/23/16.
////  Copyright © 2016 Season02. All rights reserved.
////
//
//#import "ThirdPartAlipay.h"
//#import "SeAlertView.h"
//#import "AFNetworking.h"
////#import "MGCTabBarController.h"
//
//#import "MGCSettingDone.h"
//
//#import <OverRun-Swift.h>
//
////static MGCPayViewController* payView;
//static NSString* buyhistoryid;
//static NSInteger timerCount = 0;
//
//static UIViewController* reactView;
//
//@implementation ThirdPartAlipay
//
////+(void)setupPayView:(MGCPayViewController*)view
////{
////    payView = view;
////}
//
//+(void)setupView:(UIViewController*)view
//{
//    reactView = view;
//}
//
//
//+(void)setBuyHistoryId:(NSString*)buyhistory
//{
//    buyhistoryid = buyhistory;
//}
//
//+(void)alipay:(NSString*)singedOrder
//{
//    [[AlipaySDK defaultService] payOrder:singedOrder fromScheme:SeThirdKeyAli_Scheme callback:^(NSDictionary *resultDic)
//    {
//        //NSLog(@"alipay_reslut = %@",resultDic);
//        
//        [self getDone:[resultDic valueForKey:@"resultStatus"]];
//    }];
//}
//
//+ (BOOL)handAliUrl:(NSURL *)url
//{
//    //如果极简开发包不可用，会跳转支付宝钱包进行支付，需要将支付宝钱包的支付结果回传给开发包
//    if ([url.host isEqualToString:@"safepay"])
//    {
//        [[AlipaySDK defaultService] processOrderWithPaymentResult:url standbyCallback:^(NSDictionary *resultDic)
//        {
//            //【由于在跳转支付宝客户端支付的过程中，商户app在后台很可能被系统kill了，所以pay接口的callback就会失效，请商户对standbyCallback返回的回调结果进行处理,就是在这个方法里面处理跟callback一样的逻辑】
//            NSLog(@"result_1 = %@",resultDic);
//            
//            [self getDone:[resultDic valueForKey:@"resultStatus"]];
//        }];
//    }
//    
//    if ([url.host isEqualToString:@"platformapi"])//支付宝钱包快登授权返回authCode
//    {
//        [[AlipaySDK defaultService] processAuthResult:url standbyCallback:^(NSDictionary *resultDic)
//        {
//            //【由于在跳转支付宝客户端支付的过程中，商户app在后台很可能被系统kill了，所以pay接口的callback就会失效，请商户对standbyCallback返回的回调结果进行处理,就是在这个方法里面处理跟callback一样的逻辑】
//            NSLog(@"result_2 = %@",resultDic);
//            
//            [self getDone:[resultDic valueForKey:@"resultStatus"]];
//        }];
//    }
//    return YES;
//}
//
//+(void)checkStatus:(NSString*)buyhistoryid callback:(PayStatusBlock)callback
//{
//    if(timerCount > 10)
//        callback(false,@"");
//    
//    NSMutableDictionary *params = [NSMutableDictionary dictionary];
//    NSString* prifix = CommonPay.UrlOfCheck;
//    
//    [params setObject:buyhistoryid forKey:@"buyhistoryid"];
//    
//    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    //manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
//    [manager POST:[NaFilter requestDicWithUrl:prifix par:params] parameters:params progress:nil success:^(NSURLSessionTask *task, id responseObject)
//     {
//         NSLog(@"Thirdpart pay response = %@\n", responseObject);
//         NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
//         
//         if([[dic valueForKey:@"status"] isEqualToString:@"success"])
//         {
//             timerCount = 0;
//             
//             NSString* endtime = [dic valueForKey:@"endtime"];
//             callback(true,endtime);
//         }
//         else
//         {
//             [SeAlertView scheduledTimerWithTimeInterval:0.5 repeats:NO callback:^(void)
//              {
//                  [ThirdPartAlipay checkStatus];
//              }];
//         }
//         
//     }
//     failure:^(NSURLSessionTask *operation, NSError *error)
//     {
//         //请求失败后内容
//         NSLog(@"获取用户信息时出错 = %@", error);
//         callback(false,@"");
//     }];
//    
//    timerCount++;
//}
//
//+(void)checkStatus
//{
////    if(timerCount > 10)
////    {
////        if(payView != nil)
////        {
//////            [payView showHUDError:NSLocalizedString(@"payFailed", @"")];
////            [payView hideHUD];
////            
////            ReactLittleWindowController* react = [[ReactLittleWindowController alloc]init];
////            react.parentView = payView;
////            react.type = WindowTypePayFailed;
////            [react showup];
////        }
////        else
////            [(ReactCenterViewController*)reactView payCallback:false];
////        
////        return;
////    }
//    
//    NSMutableDictionary *params = [NSMutableDictionary dictionary];
//    
//    //NSString* prifix = @"http://192.168.3.107:8080/gmhy/unionAppPay";
//    NSString* prifix = CommonPay.UrlOfCheck;
//    
//    [params setObject:buyhistoryid forKey:@"buyhistoryid"];
//    
//    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
//    //manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/plain"];
//    [manager POST:[NaFilter requestDicWithUrl:prifix par:params] parameters:params progress:nil success:^(NSURLSessionTask *task, id responseObject)
//    {
//         NSLog(@"Thirdpart pay response = %@\n", responseObject);
//         NSDictionary *dic = [NSDictionary dictionaryWithDictionary:responseObject];
//         
//         if([[dic valueForKey:@"status"] isEqualToString:@"success"])
//         {
//             NSString* endtime = [dic valueForKey:@"endtime"];
//             
//             timerCount = 0;
//             
//             if(payView != nil)
//             {
//                 //[payView showHUDSuccess:NSLocalizedString(@"paySuccess", @"")];
//                 [payView hideHUD];
//                 
//                 ReactLittleWindowController* react = [[ReactLittleWindowController alloc]init];
//                 react.parentView = payView;
//                 react.type = WindowTypePayDone;
//                 [react showup];
//                 
//                 [SeAlertView scheduledTimerWithTimeInterval:1 repeats:NO callback:^(void)
//                  {
//                      if(nil != endtime)
//                      [MGCSettingDone setVipEndTime:endtime];
//                      
//                      //UIApplication.sharedApplication.delegate.window.rootViewController = [[MGCTabBarController alloc] init];
//                  }];
//             }
//             else if(reactView != nil)
//                 [(ReactCenterViewController*)reactView payCallback:true];
//         }
//         else
//         {
//             [SeAlertView scheduledTimerWithTimeInterval:0.5 repeats:NO callback:^(void)
//              {
//                  [ThirdPartAlipay checkStatus];
//              }];
//         }
//         
//     }
//     failure:^(NSURLSessionTask *operation, NSError *error)
//     {
//         //请求失败后内容
//         timerCount = 0;
//         NSLog(@"获取用户信息时出错 = %@", error);
//     }];
//    
//    timerCount++;
//}
//
//+(void)getDone:(NSString*)status
//{
//    if([status isEqualToString:@"9000"])
//    {
////        if(payView != nil)
////        {
////            [SeAlertView scheduledTimerWithTimeInterval:0.5 repeats:NO callback:^(void)
////             {
////                 [ThirdPartAlipay checkStatus];
////             }];
////        }
////        else
////            [(ReactCenterViewController*)reactView payCallback:true buyId:buyhistoryid];
//    }
//    else
//    {
////        if(payView != nil)
////        {
//////            [payView showHUDError:NSLocalizedString(@"payFailed", @"")];
////            [payView hideHUD];
////            
////            ReactLittleWindowController* react = [[ReactLittleWindowController alloc]init];
////            react.parentView = payView;
////            react.type = WindowTypePayFailed;
////            [react showup];
////        }
////        else
////            [(ReactCenterViewController*)reactView payCallback:false];
//    }
//}
//
//@end
